package com.pdd.mapper;

import com.pdd.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CourseMapper {

    //查询全部
    @Select("select * from course;")
    //直接在接口的方法上方写对应的注解
    List<Course> getAllCourses();

    //根据编号找一门课程
    @Select("select *from course where c_id =#{cId}")
    @Results({
            @Result(column = "teacher_id", property = "teacherId"),
            @Result(column = "t_id", property = "teacher", one = @One(select = "com.pdd.mapper.TeacherMapper.selectOneTeacher"))

    })
    Course getOneCourse(int id);

    //根据编号删除一门课程
    @Delete("delete from course where c_id=#{cId}")
    int removeCourse(int id);

    //添加课程
    @Insert("insert into course(c_name, t_id) value (#{cName},#{tId})")
    int addCourse(Course course);

    //修改课程
    @Update("update course set c_name=#{cName},t_id=#{tId}")
    int editCourse(Course course);


}
